﻿using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Csla;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

namespace Model
{
    [Serializable()]
    public class HOSOBO : Csla.BusinessBase<HOSOBO>
    {
        #region Business Properties

        private int? _HSID = null;
        public int? HSID
        {
            get { return this._HSID; }
            set { this._HSID = value; PropertyHasChanged("HSID"); }
        }

        private DateTime? _NNHS = DateTime.Now;
        public DateTime? NNHS
        {
            get { return this._NNHS; }
            set { this._NNHS = value; PropertyHasChanged("NNHS"); }
        }

        private string _PCMS = null;
        public string PCMS
        {
            get { return this._PCMS; }
            set { this._PCMS = value; PropertyHasChanged("PCMS"); }
        }

        private DateTime? _PCNC = null;
        public DateTime? PCNC
        {
            get { return this._PCNC; }
            set { this._PCNC = value; PropertyHasChanged("PCNC"); }
        }

        private bool? _LPTB = false;
        public bool? LPTB
        {
            get { return this._LPTB; }
            set { this._LPTB = value; PropertyHasChanged("LPTB"); }
        }

        private bool? _TSDD = false;
        public bool? TSDD
        {
            get { return this._TSDD; }
            set { this._TSDD = value; PropertyHasChanged("TSDD"); }
        }

        private bool? _BSLP = false;
        public bool? BSLP
        {
            get { return this._BSLP; }
            set { this._BSLP = value; PropertyHasChanged("BSLP"); }
        }

        private bool? _TNDN = false;
        public bool? TNDN
        {
            get { return this._TNDN; }
            set { this._TNDN = value; PropertyHasChanged("TNDN"); }
        }

        private bool? _TNCN = false;
        public bool? TNCN
        {
            get { return this._TNCN; }
            set { this._TNCN = value; PropertyHasChanged("TNCN"); }
        }

        private string _SOTD = null;
        public string SOTD
        {
            get { return this._SOTD; }
            set { this._SOTD = value; PropertyHasChanged("SOTD"); }
        }

        private string _SOBD = null;
        public string SOBD
        {
            get { return this._SOBD; }
            set { this._SOBD = value; PropertyHasChanged("SOBD"); }
        }

        private int? _DPID = null;
        public int? DPID
        {
            get { return this._DPID; }
            set { this._DPID = value; PropertyHasChanged("DPID"); }
        }

        private string _DCTD = null;
        public string DCTD
        {
            get { return this._DCTD; }
            set { this._DCTD = value; PropertyHasChanged("DCTD"); }
        }

        private double? _DTTD = 0;
        public double? DTTD
        {
            get { return this._DTTD; }
            set { this._DTTD = value; PropertyHasChanged("DTTD"); }
        }

        private string _LDKV = null;
        public string LDKV
        {
            get { return this._LDKV; }
            set { this._LDKV = value; PropertyHasChanged("LDKV"); }
        }

        private string _VITR = null;
        public string VITR
        {
            get { return this._VITR; }
            set { this._VITR = value; PropertyHasChanged("VITR"); }
        }

        private string _LDAT = null;
        public string LDAT
        {
            get { return this._LDAT; }
            set { this._LDAT = value; PropertyHasChanged("LDAT"); }
        }

        private string _BGTS = null;
        public string BGTS
        {
            get { return this._BGTS; }
            set { this._BGTS = value; PropertyHasChanged("BGTS"); }
        }

        private string _MABG = null;
        public string MABG
        {
            get { return this._MABG; }
            set { this._MABG = value; PropertyHasChanged("MABG"); }
        }

        private string _DCBG = null;
        public string DCBG
        {
            get { return this._DCBG; }
            set { this._DCBG = value; PropertyHasChanged("DCBG"); }
        }

        private string _BNTS = null;
        public string BNTS
        {
            get { return this._BNTS; }
            set { this._BNTS = value; PropertyHasChanged("BNTS"); }
        }

        private string _MABN = null;
        public string MABN
        {
            get { return this._MABN; }
            set { this._MABN = value; PropertyHasChanged("MABN"); }
        }

        private string _DCBN = null;
        public string DCBN
        {
            get { return this._DCBN; }
            set { this._DCBN = value; PropertyHasChanged("DCBN"); }
        }

        private string _NKKH = null;
        public string NKKH
        {
            get { return this._NKKH; }
            set { this._NKKH = value; PropertyHasChanged("NKKH"); }
        }

        private string _DCKH = null;
        public string DCKH
        {
            get { return this._DCKH; }
            set { this._DCKH = value; PropertyHasChanged("DCKH"); }
        }

        private double? _TRGD = 0;
        public double? TRGD
        {
            get { return this._TRGD; }
            set { this._TRGD = value; PropertyHasChanged("TRGD"); }
        }

        private double? _TRGN = 0;
        public double? TRGN
        {
            get { return this._TRGN; }
            set { this._TRGN = value; PropertyHasChanged("TRGN"); }
        }

        private int? _NGID = null;
        public int? NGID
        {
            get { return this._NGID; }
            set { this._NGID = value; PropertyHasChanged("NGID"); }
        }

        private bool? _SDD1 = false;
        public bool? SDD1
        {
            get { return this._SDD1; }
            set { this._SDD1 = value; PropertyHasChanged("SDD1"); }
        }

        private bool? _SDD5 = false;
        public bool? SDD5
        {
            get { return this._SDD5; }
            set { this._SDD5 = value; PropertyHasChanged("SDD5"); }
        }

        private bool? _CL21 = false;
        public bool? CL21
        {
            get { return this._CL21; }
            set { this._CL21 = value; PropertyHasChanged("CL21"); }
        }

        private bool? _CL25 = false;
        public bool? CL25
        {
            get { return this._CL25; }
            set { this._CL25 = value; PropertyHasChanged("CL25"); }
        }

        private bool? _GD50 = false;
        public bool? GD50
        {
            get { return this._GD50; }
            set { this._GD50 = value; PropertyHasChanged("GD50"); }
        }

        private bool? _MCNK = false;
        public bool? MCNK
        {
            get { return this._MCNK; }
            set { this._MCNK = value; PropertyHasChanged("MCNK"); }
        }

        private string _VBID = null;
        public string VBID
        {
            get { return this._VBID; }
            set { this._VBID = value; PropertyHasChanged("VBID"); }
        }

        private DateTime? _VBNC = null;
        public DateTime? VBNC
        {
            get { return this._VBNC; }
            set { this._VBNC = value; PropertyHasChanged("VBNC"); }
        }

        private string _QDGD = null;
        public string QDGD
        {
            get { return this._QDGD; }
            set { this._QDGD = value; PropertyHasChanged("QDGD"); }
        }

        private string _CQGD = null;
        public string CQGD
        {
            get { return this._CQGD; }
            set { this._CQGD = value; PropertyHasChanged("CQGD"); }
        }

        private int? _TDID = null;
        public int? TDID
        {
            get { return this._TDID; }
            set { this._TDID = value; PropertyHasChanged("TDID"); }
        }

        private int? _DDID = null;
        public int? DDID
        {
            get { return this._DDID; }
            set { this._DDID = value; PropertyHasChanged("DDID"); }
        }

        private int? _VTLD = null;
        public int? VTLD
        {
            get { return this._VTLD; }
            set { this._VTLD = value; PropertyHasChanged("VTLD"); }
        }

        private int? _HSCL = null;
        public int? HSCL
        {
            get { return this._HSCL; }
            set { this._HSCL = value; PropertyHasChanged("HSCL"); }
        }

        private int? _HSHT = null;
        public int? HSHT
        {
            get { return this._HSHT; }
            set { this._HSHT = value; PropertyHasChanged("HSHT"); }
        }

        private int? _HSDB = null;
        public int? HSDB
        {
            get { return this._HSDB; }
            set { this._HSDB = value; PropertyHasChanged("HSDB"); }
        }

        private int? _TLGG = null;
        public int? TLGG
        {
            get { return this._TLGG; }
            set { this._TLGG = value; PropertyHasChanged("TLGG"); }
        }

        private bool? _CTSX = false;
        public bool? CTSX
        {
            get { return this._CTSX; }
            set { this._CTSX = value; PropertyHasChanged("CTSX"); }
        }

        private double? _SXKD = 0;
        public double? SXKD
        {
            get { return this._SXKD; }
            set { this._SXKD = value; PropertyHasChanged("SXKD"); }
        }

        private double? _GCHC = 0;
        public double? GCHC
        {
            get { return this._GCHC; }
            set { this._GCHC = value; PropertyHasChanged("GCHC"); }
        }

        private double? _CLGD = 0;
        public double? CLGD
        {
            get { return this._CLGD; }
            set { this._CLGD = value; PropertyHasChanged("CLGD"); }
        }

        private double? _G1M2 = 0;
        public double? G1M2
        {
            get { return this._G1M2; }
            set { this._G1M2 = value; PropertyHasChanged("G1M2"); }
        }

        private double? _TONG = 0;
        public double? TONG
        {
            get { return this._TONG; }
            set { this._TONG = value; PropertyHasChanged("TONG"); }
        }

        private string _GCHU = null;
        public string GCHU
        {
            get { return this._GCHU; }
            set { this._GCHU = value; PropertyHasChanged("GCHU"); }
        }

        private string _ZTD = null;
        public string ZTD
        {
            get { return this._ZTD; }
            set { this._ZTD = value; PropertyHasChanged("ZTD"); }
        }

        private string _ZDD = null;
        public string ZDD
        {
            get { return this._ZDD; }
            set { this._ZDD = value; PropertyHasChanged("ZDD"); }
        }

        private double? _ZHS = 0;
        public double? ZHS
        {
            get { return this._ZHS; }
            set { this._ZHS = value; PropertyHasChanged("ZHS"); }
        }

        private int? _ZVT = 0;
        public int? ZVT
        {
            get { return this._ZVT; }
            set { this._ZVT = value; PropertyHasChanged("ZVT"); }
        }

        private double? _ZDGC = 0;
        public double? ZDGC
        {
            get { return this._ZDGC; }
            set { this._ZDGC = value; PropertyHasChanged("ZDGC"); }
        }

        private string _ZTLGG_T = null;
        public string ZTLGG_T
        {
            get { return this._ZTLGG_T; }
            set { this._ZTLGG_T = value; PropertyHasChanged("ZTLGG_T"); }
        }

        private double? _ZTLGG_V = 0;
        public double? ZTLGG_V
        {
            get { return this._ZTLGG_V; }
            set { this._ZTLGG_V = value; PropertyHasChanged("ZTLGG_V"); }
        }

        private string _ZHSCL_T = null;
        public string ZHSCL_T
        {
            get { return this._ZHSCL_T; }
            set { this._ZHSCL_T = value; PropertyHasChanged("ZHSCL_T"); }
        }

        private double? _ZHSCL_V = 0;
        public double? ZHSCL_V
        {
            get { return this._ZHSCL_V; }
            set { this._ZHSCL_V = value; PropertyHasChanged("ZHSCL_V"); }
        }

        private string _ZHSHT_T = null;
        public string ZHSHT_T
        {
            get { return this._ZHSHT_T; }
            set { this._ZHSHT_T = value; PropertyHasChanged("ZHSHT_T"); }
        }

        private double? _ZHSHT_V = null;
        public double? ZHSHT_V
        {
            get { return this._ZHSHT_V; }
            set { this._ZHSHT_V = value; PropertyHasChanged("ZHSHT_V"); }
        }

        private string _ZHSDB_T = null;
        public string ZHSDB_T
        {
            get { return this._ZHSDB_T; }
            set { this._ZHSDB_T = value; PropertyHasChanged("ZHSDB_T"); }
        }

        private double? _ZHSDB_V = 0;
        public double? ZHSDB_V
        {
            get { return this._ZHSDB_V; }
            set { this._ZHSDB_V = value; PropertyHasChanged("ZHSDB_V"); }
        }

        private double? _GIAP = 0;
        public double? GIAP
        {
            get { return this._GIAP; }
            set { this._GIAP = value; PropertyHasChanged("GIAP"); }
        }

        private double? _GIAO = 0;
        public double? GIAO
        {
            get { return this._GIAO; }
            set { this._GIAO = value; PropertyHasChanged("GIAO"); }
        }

        private int? _USRC = Session.LoginID;
        public int? USRC
        {
            get { return this._USRC; }
            set { this._USRC = value; PropertyHasChanged("USRC"); }
        }

        private DateTime? _DATC = DateTime.MaxValue;
        public DateTime? DATC
        {
            get { return this._DATC; }
            set { this._DATC = value; PropertyHasChanged("DATC"); }
        }

        private int? _USRM = null;
        public int? USRM
        {
            get { return this._USRM; }
            set { this._USRM = value; PropertyHasChanged("USRM"); }
        }

        private DateTime? _DATM = null;
        public DateTime? DATM
        {
            get { return this._DATM; }
            set { this._DATM = value; PropertyHasChanged("DATM"); }
        }

        private bool? _DELE = false;
        public bool? DELE
        {
            get { return this._DELE; }
            set { this._DELE = value; PropertyHasChanged("DELE"); }
        }

        private int? _STT0 = 0;
        public int? STT0
        {
            get { return _STT0; }
            set { _STT0 = value; PropertyHasChanged("STT0"); }
        }

        protected override object GetIdValue()
        {
            return _HSID.Value;
        }
        #endregion Business Properties
        //==========================================================================

        #region Factory Methods
        public void SetIsNew()
        {
            MarkNew();
        }

        public void SetIsOld()
        {
            MarkOld();
        }

        public void SetIsDirty()
        {
            MarkDirty();
        }

        public object GetValue(string fieldName)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            return propInfo.GetValue(this, null);
        }

        public void SetValue(string fieldName, object value)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            propInfo.SetValue(this, value, null);
            MarkDirty();
        }

        private static int newHSID = -1;
        private HOSOBO()
        {
            _HSID = newHSID--;
        }

        public HOSOBO(SqlDataReader dataReader)
        {
            MarkAsChild();
            Fetch(dataReader);
            MarkOld();
        }

        public HOSOBO(SqlDataReader dataReader, bool isRoot)
        {
            if (!isRoot)
                MarkAsChild();
            Fetch(dataReader);
            MarkOld();
        }

        public static HOSOBO NewRootHOSOBO()
        {
            return DataPortal.Create<HOSOBO>(new RootCriteria());
        }

        internal static HOSOBO NewChildHOSOBO()
        {
            return DataPortal.Create<HOSOBO>(new ChildCriteria());
        }

        public static HOSOBO GetRootHOSOBO(int _HSID)
        {
            return DataPortal.Fetch<HOSOBO>(new RootCriteria(_HSID));
        }

        public static HOSOBO GetRootHOSOBOByWhere(string where)
        {
            return DataPortal.Fetch<HOSOBO>(where);
        }

        internal static HOSOBO GetChildHOSOBO(SqlDataReader dataReader)
        {
            return new HOSOBO(dataReader);
        }

        public static void DeleteHOSOBO(int _HSID)
        {
            DataPortal.Delete(new RootCriteria(_HSID));
        }

        public static void DeleteHOSOBO(int _HSID, bool directDelete)
        {
            DataPortal.Delete(new RootCriteria(_HSID, directDelete));
        }
        #endregion Factory Methods
        //==========================================================================

        #region Criteria
        [Serializable()]
        public class RootCriteria
        {
            public int HSID;
            public bool directDelete = false;
            public RootCriteria(int _HSID)
            {
                this.HSID = _HSID;
                this.directDelete = false;
            }

            public RootCriteria(int _HSID, bool directDelete)
            {
                this.HSID = _HSID;
                this.directDelete = directDelete;
            }

            public RootCriteria() { }
        }

        [Serializable()]
        public class ChildCriteria
        {
            public int HSID;
            public bool directDelete = false;
            public ChildCriteria(int _HSID)
            {
                this.HSID = _HSID;
                this.directDelete = false;
            }

            public ChildCriteria(int _HSID, bool directDelete)
            {
                this.HSID = _HSID;
                this.directDelete = directDelete;
            }

            public ChildCriteria() { }
        }
        #endregion Criteria
        //==========================================================================

        #region Create
        [RunLocal]
        private void DataPortal_Create(RootCriteria criteria)
        {
        }

        private void DataPortal_Create(ChildCriteria criteria)
        {
            MarkAsChild();
            ValidationRules.CheckRules();
        }

        #endregion Create
        //==========================================================================

        #region Fetch
        [Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Fetch(RootCriteria criteria)
        {
            this.Execute_Fetch(criteria);
        }

        protected void DataPortal_Fetch(string where)
        {
            this.Execute_Fetch(where);
        }

        protected void Execute_Fetch(RootCriteria criteria)
        {
            this.This_Fetch(criteria);
        }

        protected void Execute_Fetch(string where)
        {
            this.This_Fetch(where);
        }

        private void This_Fetch(RootCriteria criteria)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("HOSOBO_GetBO");
            db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, "[HSID] = " + criteria.HSID);
            using (SqlDataReader dataReader = (SqlDataReader)db.ExecuteReader(cmd))
            {
                if (dataReader.Read())
                    Fetch(dataReader);
            }
        }

        private void This_Fetch(string where)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("HOSOBO_GetBO");
            db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, where);
            using (SqlDataReader dataReader = (SqlDataReader)db.ExecuteReader(cmd))
            {
                if (dataReader.Read())
                    Fetch(dataReader);
            }
        }

        private void Fetch(SqlDataReader dataReader)
        {
            if (!(dataReader["HSID"] is DBNull))
                this._HSID = (int)dataReader["HSID"];
            if (!(dataReader["NNHS"] is DBNull))
                this._NNHS = (DateTime)dataReader["NNHS"];
            if (!(dataReader["PCMS"] is DBNull))
                this._PCMS = (string)dataReader["PCMS"];
            if (!(dataReader["PCNC"] is DBNull))
                this._PCNC = (DateTime)dataReader["PCNC"];
            if (!(dataReader["LPTB"] is DBNull))
                this._LPTB = (bool)dataReader["LPTB"];
            if (!(dataReader["TSDD"] is DBNull))
                this._TSDD = (bool)dataReader["TSDD"];
            if (!(dataReader["BSLP"] is DBNull))
                this._BSLP = (bool)dataReader["BSLP"];
            if (!(dataReader["TNDN"] is DBNull))
                this._TNDN = (bool)dataReader["TNDN"];
            if (!(dataReader["TNCN"] is DBNull))
                this._TNCN = (bool)dataReader["TNCN"];
            if (!(dataReader["SOTD"] is DBNull))
                this._SOTD = (string)dataReader["SOTD"];
            if (!(dataReader["SOBD"] is DBNull))
                this._SOBD = (string)dataReader["SOBD"];
            if (!(dataReader["DPID"] is DBNull))
                this._DPID = (int)dataReader["DPID"];
            if (!(dataReader["DCTD"] is DBNull))
                this._DCTD = (string)dataReader["DCTD"];
            if (!(dataReader["DTTD"] is DBNull))
                this._DTTD = (double)dataReader["DTTD"];
            if (!(dataReader["LDKV"] is DBNull))
                this._LDKV = (string)dataReader["LDKV"];
            if (!(dataReader["VITR"] is DBNull))
                this._VITR = (string)dataReader["VITR"];
            if (!(dataReader["LDAT"] is DBNull))
                this._LDAT = (string)dataReader["LDAT"];
            if (!(dataReader["BGTS"] is DBNull))
                this._BGTS = (string)dataReader["BGTS"];
            if (!(dataReader["MABG"] is DBNull))
                this._MABG = (string)dataReader["MABG"];
            if (!(dataReader["DCBG"] is DBNull))
                this._DCBG = (string)dataReader["DCBG"];
            if (!(dataReader["BNTS"] is DBNull))
                this._BNTS = (string)dataReader["BNTS"];
            if (!(dataReader["MABN"] is DBNull))
                this._MABN = (string)dataReader["MABN"];
            if (!(dataReader["DCBN"] is DBNull))
                this._DCBN = (string)dataReader["DCBN"];
            if (!(dataReader["NKKH"] is DBNull))
                this._NKKH = (string)dataReader["NKKH"];
            if (!(dataReader["DCKH"] is DBNull))
                this._DCKH = (string)dataReader["DCKH"];
            if (!(dataReader["TRGD"] is DBNull))
                this._TRGD = (double)dataReader["TRGD"];
            if (!(dataReader["TRGN"] is DBNull))
                this._TRGN = (double)dataReader["TRGN"];
            if (!(dataReader["NGID"] is DBNull))
                this._NGID = (int)dataReader["NGID"];
            if (!(dataReader["SDD1"] is DBNull))
                this._SDD1 = (bool)dataReader["SDD1"];
            if (!(dataReader["SDD5"] is DBNull))
                this._SDD5 = (bool)dataReader["SDD5"];
            if (!(dataReader["CL21"] is DBNull))
                this._CL21 = (bool)dataReader["CL21"];
            if (!(dataReader["CL25"] is DBNull))
                this._CL25 = (bool)dataReader["CL25"];
            if (!(dataReader["GD50"] is DBNull))
                this._GD50 = (bool)dataReader["GD50"];
            if (!(dataReader["MCNK"] is DBNull))
                this._MCNK = (bool)dataReader["MCNK"];
            if (!(dataReader["VBID"] is DBNull))
                this._VBID = (string)dataReader["VBID"];
            if (!(dataReader["VBNC"] is DBNull))
                this._VBNC = (DateTime)dataReader["VBNC"];
            if (!(dataReader["QDGD"] is DBNull))
                this._QDGD = (string)dataReader["QDGD"];
            if (!(dataReader["CQGD"] is DBNull))
                this._CQGD = (string)dataReader["CQGD"];
            if (!(dataReader["TDID"] is DBNull))
                this._TDID = (int)dataReader["TDID"];
            if (!(dataReader["DDID"] is DBNull))
                this._DDID = (int)dataReader["DDID"];
            if (!(dataReader["VTLD"] is DBNull))
                this._VTLD = (int)dataReader["VTLD"];
            if (!(dataReader["HSCL"] is DBNull))
                this._HSCL = (int)dataReader["HSCL"];
            if (!(dataReader["HSHT"] is DBNull))
                this._HSHT = (int)dataReader["HSHT"];
            if (!(dataReader["HSDB"] is DBNull))
                this._HSDB = (int)dataReader["HSDB"];
            if (!(dataReader["TLGG"] is DBNull))
                this._TLGG = (int)dataReader["TLGG"];
            if (!(dataReader["CTSX"] is DBNull))
                this._CTSX = (bool)dataReader["CTSX"];
            if (!(dataReader["SXKD"] is DBNull))
                this._SXKD = (double)dataReader["SXKD"];
            if (!(dataReader["GCHC"] is DBNull))
                this._GCHC = (double)dataReader["GCHC"];
            if (!(dataReader["CLGD"] is DBNull))
                this._CLGD = (double)dataReader["CLGD"];
            if (!(dataReader["G1M2"] is DBNull))
                this._G1M2 = (double)dataReader["G1M2"];
            if (!(dataReader["TONG"] is DBNull))
                this._TONG = (double)dataReader["TONG"];
            if (!(dataReader["GCHU"] is DBNull))
                this._GCHU = (string)dataReader["GCHU"];
            if (!(dataReader["ZTD"] is DBNull))
                this._ZTD = (string)dataReader["ZTD"];
            if (!(dataReader["ZDD"] is DBNull))
                this._ZDD = (string)dataReader["ZDD"];
            if (!(dataReader["ZHS"] is DBNull))
                this._ZHS = (double)dataReader["ZHS"];
            if (!(dataReader["ZVT"] is DBNull))
                this._ZVT = (int)dataReader["ZVT"];
            if (!(dataReader["ZDGC"] is DBNull))
                this._ZDGC = (double)dataReader["ZDGC"];
            if (!(dataReader["ZTLGG_T"] is DBNull))
                this._ZTLGG_T = (string)dataReader["ZTLGG_T"];
            if (!(dataReader["ZTLGG_V"] is DBNull))
                this._ZTLGG_V = (double)dataReader["ZTLGG_V"];
            if (!(dataReader["ZHSCL_T"] is DBNull))
                this._ZHSCL_T = (string)dataReader["ZHSCL_T"];
            if (!(dataReader["ZHSCL_V"] is DBNull))
                this._ZHSCL_V = (double)dataReader["ZHSCL_V"];
            if (!(dataReader["ZHSHT_T"] is DBNull))
                this._ZHSHT_T = (string)dataReader["ZHSHT_T"];
            if (!(dataReader["ZHSHT_V"] is DBNull))
                this._ZHSHT_V = (double)dataReader["ZHSHT_V"];
            if (!(dataReader["ZHSDB_T"] is DBNull))
                this._ZHSDB_T = (string)dataReader["ZHSDB_T"];
            if (!(dataReader["ZHSDB_V"] is DBNull))
                this._ZHSDB_V = (double)dataReader["ZHSDB_V"];
            if (!(dataReader["GIAP"] is DBNull))
                this._GIAP = (double)dataReader["GIAP"];
            if (!(dataReader["GIAO"] is DBNull))
                this._GIAO = (double)dataReader["GIAO"];
            if (!(dataReader["USRC"] is DBNull))
                this._USRC = (int)dataReader["USRC"];
            if (!(dataReader["DATC"] is DBNull))
                this._DATC = (DateTime)dataReader["DATC"];
            if (!(dataReader["USRM"] is DBNull))
                this._USRM = (int)dataReader["USRM"];
            if (!(dataReader["DATM"] is DBNull))
                this._DATM = (DateTime)dataReader["DATM"];
            if (!(dataReader["DELE"] is DBNull))
                this._DELE = (bool)dataReader["DELE"];

        }
        #endregion Fetch
        //==========================================================================

        #region Insert
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Insert()
        {
            this.Execute_Insert();
        }

        protected void Execute_Insert()
        {
            this.This_Insert();
        }

        private void This_Insert()
        {
            this._USRC = Session.LoginID;
            this._DATC = DateTime.MaxValue;
            this._USRM = null;
            this._DATM = null;
            this._DELE = false;

            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("HOSOBO_InsertBO");
            db.AddInParameter(cmd, "@NNHS", SqlDbType.DateTime, this._NNHS);
            db.AddInParameter(cmd, "@PCMS", SqlDbType.NVarChar, this._PCMS);
            db.AddInParameter(cmd, "@PCNC", SqlDbType.DateTime, this._PCNC);
            db.AddInParameter(cmd, "@LPTB", SqlDbType.Bit, this._LPTB);
            db.AddInParameter(cmd, "@TSDD", SqlDbType.Bit, this._TSDD);
            db.AddInParameter(cmd, "@BSLP", SqlDbType.Bit, this._BSLP);
            db.AddInParameter(cmd, "@TNDN", SqlDbType.Bit, this._TNDN);
            db.AddInParameter(cmd, "@TNCN", SqlDbType.Bit, this._TNCN);
            db.AddInParameter(cmd, "@SOTD", SqlDbType.NVarChar, this._SOTD);
            db.AddInParameter(cmd, "@SOBD", SqlDbType.NVarChar, this._SOBD);
            db.AddInParameter(cmd, "@DPID", SqlDbType.Int, this._DPID);
            db.AddInParameter(cmd, "@DCTD", SqlDbType.NVarChar, this._DCTD);
            db.AddInParameter(cmd, "@DTTD", SqlDbType.Float, this._DTTD);
            db.AddInParameter(cmd, "@LDKV", SqlDbType.NVarChar, this._LDKV);
            db.AddInParameter(cmd, "@VITR", SqlDbType.NVarChar, this._VITR);
            db.AddInParameter(cmd, "@LDAT", SqlDbType.NVarChar, this._LDAT);
            db.AddInParameter(cmd, "@BGTS", SqlDbType.NVarChar, this._BGTS);
            db.AddInParameter(cmd, "@MABG", SqlDbType.NVarChar, this._MABG);
            db.AddInParameter(cmd, "@DCBG", SqlDbType.NVarChar, this._DCBG);
            db.AddInParameter(cmd, "@BNTS", SqlDbType.NVarChar, this._BNTS);
            db.AddInParameter(cmd, "@MABN", SqlDbType.NVarChar, this._MABN);
            db.AddInParameter(cmd, "@DCBN", SqlDbType.NVarChar, this._DCBN);
            db.AddInParameter(cmd, "@NKKH", SqlDbType.NVarChar, this._NKKH);
            db.AddInParameter(cmd, "@DCKH", SqlDbType.NVarChar, this._DCKH);
            db.AddInParameter(cmd, "@TRGD", SqlDbType.Float, this._TRGD);
            db.AddInParameter(cmd, "@TRGN", SqlDbType.Float, this._TRGN);
            db.AddInParameter(cmd, "@NGID", SqlDbType.Int, this._NGID);
            db.AddInParameter(cmd, "@SDD1", SqlDbType.Bit, this._SDD1);
            db.AddInParameter(cmd, "@SDD5", SqlDbType.Bit, this._SDD5);
            db.AddInParameter(cmd, "@CL21", SqlDbType.Bit, this._CL21);
            db.AddInParameter(cmd, "@CL25", SqlDbType.Bit, this._CL25);
            db.AddInParameter(cmd, "@GD50", SqlDbType.Bit, this._GD50);
            db.AddInParameter(cmd, "@MCNK", SqlDbType.Bit, this._MCNK);
            db.AddInParameter(cmd, "@VBID", SqlDbType.VarChar, this._VBID);
            db.AddInParameter(cmd, "@VBNC", SqlDbType.DateTime, this._VBNC);
            db.AddInParameter(cmd, "@QDGD", SqlDbType.NVarChar, this._QDGD);
            db.AddInParameter(cmd, "@CQGD", SqlDbType.NVarChar, this._CQGD);
            db.AddInParameter(cmd, "@TDID", SqlDbType.Int, this._TDID);
            db.AddInParameter(cmd, "@DDID", SqlDbType.Int, this._DDID);
            db.AddInParameter(cmd, "@VTLD", SqlDbType.Int, this._VTLD);
            db.AddInParameter(cmd, "@HSCL", SqlDbType.Int, this._HSCL);
            db.AddInParameter(cmd, "@HSHT", SqlDbType.Int, this._HSHT);
            db.AddInParameter(cmd, "@HSDB", SqlDbType.Int, this._HSDB);
            db.AddInParameter(cmd, "@TLGG", SqlDbType.Int, this._TLGG);
            db.AddInParameter(cmd, "@CTSX", SqlDbType.Bit, this._CTSX);
            db.AddInParameter(cmd, "@SXKD", SqlDbType.Float, this._SXKD);
            db.AddInParameter(cmd, "@GCHC", SqlDbType.Float, this._GCHC);
            db.AddInParameter(cmd, "@CLGD", SqlDbType.Float, this._CLGD);
            db.AddInParameter(cmd, "@G1M2", SqlDbType.Float, this._G1M2);
            db.AddInParameter(cmd, "@TONG", SqlDbType.Float, this._TONG);
            db.AddInParameter(cmd, "@GCHU", SqlDbType.NVarChar, this._GCHU);
            db.AddInParameter(cmd, "@ZTD", SqlDbType.NVarChar, this._ZTD);
            db.AddInParameter(cmd, "@ZDD", SqlDbType.NVarChar, this._ZDD);
            db.AddInParameter(cmd, "@ZHS", SqlDbType.Float, this._ZHS);
            db.AddInParameter(cmd, "@ZVT", SqlDbType.Int, this._ZVT);
            db.AddInParameter(cmd, "@ZDGC", SqlDbType.Float, this._ZDGC);
            db.AddInParameter(cmd, "@ZTLGG_T", SqlDbType.NVarChar, this._ZTLGG_T);
            db.AddInParameter(cmd, "@ZTLGG_V", SqlDbType.Float, this._ZTLGG_V);
            db.AddInParameter(cmd, "@ZHSCL_T", SqlDbType.NVarChar, this._ZHSCL_T);
            db.AddInParameter(cmd, "@ZHSCL_V", SqlDbType.Float, this._ZHSCL_V);
            db.AddInParameter(cmd, "@ZHSHT_T", SqlDbType.NVarChar, this._ZHSHT_T);
            db.AddInParameter(cmd, "@ZHSHT_V", SqlDbType.Float, this._ZHSHT_V);
            db.AddInParameter(cmd, "@ZHSDB_T", SqlDbType.NVarChar, this._ZHSDB_T);
            db.AddInParameter(cmd, "@ZHSDB_V", SqlDbType.Float, this._ZHSDB_V);
            db.AddInParameter(cmd, "@GIAP", SqlDbType.Float, this._GIAP);
            db.AddInParameter(cmd, "@GIAO", SqlDbType.Float, this._GIAO);
            db.AddInParameter(cmd, "@USRC", SqlDbType.Int, this._USRC);
            db.AddOutParameter(cmd, "@NewHSID", SqlDbType.Int, 10);
            db.AddOutParameter(cmd, "@NewDATC", SqlDbType.DateTime, 4);
            db.ExecuteNonQuery(cmd);
            this._HSID = (int)cmd.Parameters["@NewHSID"].Value;
            this._DATC = (DateTime)cmd.Parameters["@NewDATC"].Value;
        }
        #endregion Insert
        //==========================================================================

        #region Update
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Update()
        {
            this.Execute_Update();
        }

        protected void Execute_Update()
        {
            this.This_Update();
        }

        private void This_Update()
        {
            this._USRM = Session.LoginID;
            this._DATM = DateTime.Now;

            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("HOSOBO_UpdateBO");
            db.AddInParameter(cmd, "@HSID", SqlDbType.Int, this._HSID);
            db.AddInParameter(cmd, "@NNHS", SqlDbType.DateTime, this._NNHS);
            db.AddInParameter(cmd, "@PCMS", SqlDbType.NVarChar, this._PCMS);
            db.AddInParameter(cmd, "@PCNC", SqlDbType.DateTime, this._PCNC);
            db.AddInParameter(cmd, "@LPTB", SqlDbType.Bit, this._LPTB);
            db.AddInParameter(cmd, "@TSDD", SqlDbType.Bit, this._TSDD);
            db.AddInParameter(cmd, "@BSLP", SqlDbType.Bit, this._BSLP);
            db.AddInParameter(cmd, "@TNDN", SqlDbType.Bit, this._TNDN);
            db.AddInParameter(cmd, "@TNCN", SqlDbType.Bit, this._TNCN);
            db.AddInParameter(cmd, "@SOTD", SqlDbType.NVarChar, this._SOTD);
            db.AddInParameter(cmd, "@SOBD", SqlDbType.NVarChar, this._SOBD);
            db.AddInParameter(cmd, "@DPID", SqlDbType.Int, this._DPID);
            db.AddInParameter(cmd, "@DCTD", SqlDbType.NVarChar, this._DCTD);
            db.AddInParameter(cmd, "@DTTD", SqlDbType.Float, this._DTTD);
            db.AddInParameter(cmd, "@LDKV", SqlDbType.NVarChar, this._LDKV);
            db.AddInParameter(cmd, "@VITR", SqlDbType.NVarChar, this._VITR);
            db.AddInParameter(cmd, "@LDAT", SqlDbType.NVarChar, this._LDAT);
            db.AddInParameter(cmd, "@BGTS", SqlDbType.NVarChar, this._BGTS);
            db.AddInParameter(cmd, "@MABG", SqlDbType.NVarChar, this._MABG);
            db.AddInParameter(cmd, "@DCBG", SqlDbType.NVarChar, this._DCBG);
            db.AddInParameter(cmd, "@BNTS", SqlDbType.NVarChar, this._BNTS);
            db.AddInParameter(cmd, "@MABN", SqlDbType.NVarChar, this._MABN);
            db.AddInParameter(cmd, "@DCBN", SqlDbType.NVarChar, this._DCBN);
            db.AddInParameter(cmd, "@NKKH", SqlDbType.NVarChar, this._NKKH);
            db.AddInParameter(cmd, "@DCKH", SqlDbType.NVarChar, this._DCKH);
            db.AddInParameter(cmd, "@TRGD", SqlDbType.Float, this._TRGD);
            db.AddInParameter(cmd, "@TRGN", SqlDbType.Float, this._TRGN);
            db.AddInParameter(cmd, "@NGID", SqlDbType.Int, this._NGID);
            db.AddInParameter(cmd, "@SDD1", SqlDbType.Bit, this._SDD1);
            db.AddInParameter(cmd, "@SDD5", SqlDbType.Bit, this._SDD5);
            db.AddInParameter(cmd, "@CL21", SqlDbType.Bit, this._CL21);
            db.AddInParameter(cmd, "@CL25", SqlDbType.Bit, this._CL25);
            db.AddInParameter(cmd, "@GD50", SqlDbType.Bit, this._GD50);
            db.AddInParameter(cmd, "@MCNK", SqlDbType.Bit, this._MCNK);
            db.AddInParameter(cmd, "@VBID", SqlDbType.VarChar, this._VBID);
            db.AddInParameter(cmd, "@VBNC", SqlDbType.DateTime, this._VBNC);
            db.AddInParameter(cmd, "@QDGD", SqlDbType.NVarChar, this._QDGD);
            db.AddInParameter(cmd, "@CQGD", SqlDbType.NVarChar, this._CQGD);
            db.AddInParameter(cmd, "@TDID", SqlDbType.Int, this._TDID);
            db.AddInParameter(cmd, "@DDID", SqlDbType.Int, this._DDID);
            db.AddInParameter(cmd, "@VTLD", SqlDbType.Int, this._VTLD);
            db.AddInParameter(cmd, "@HSCL", SqlDbType.Int, this._HSCL);
            db.AddInParameter(cmd, "@HSHT", SqlDbType.Int, this._HSHT);
            db.AddInParameter(cmd, "@HSDB", SqlDbType.Int, this._HSDB);
            db.AddInParameter(cmd, "@TLGG", SqlDbType.Int, this._TLGG);
            db.AddInParameter(cmd, "@CTSX", SqlDbType.Bit, this._CTSX);
            db.AddInParameter(cmd, "@SXKD", SqlDbType.Float, this._SXKD);
            db.AddInParameter(cmd, "@GCHC", SqlDbType.Float, this._GCHC);
            db.AddInParameter(cmd, "@CLGD", SqlDbType.Float, this._CLGD);
            db.AddInParameter(cmd, "@G1M2", SqlDbType.Float, this._G1M2);
            db.AddInParameter(cmd, "@TONG", SqlDbType.Float, this._TONG);
            db.AddInParameter(cmd, "@GCHU", SqlDbType.NVarChar, this._GCHU);
            db.AddInParameter(cmd, "@ZTD", SqlDbType.NVarChar, this._ZTD);
            db.AddInParameter(cmd, "@ZDD", SqlDbType.NVarChar, this._ZDD);
            db.AddInParameter(cmd, "@ZHS", SqlDbType.Float, this._ZHS);
            db.AddInParameter(cmd, "@ZVT", SqlDbType.Int, this._ZVT);
            db.AddInParameter(cmd, "@ZDGC", SqlDbType.Float, this._ZDGC);
            db.AddInParameter(cmd, "@ZTLGG_T", SqlDbType.NVarChar, this._ZTLGG_T);
            db.AddInParameter(cmd, "@ZTLGG_V", SqlDbType.Float, this._ZTLGG_V);
            db.AddInParameter(cmd, "@ZHSCL_T", SqlDbType.NVarChar, this._ZHSCL_T);
            db.AddInParameter(cmd, "@ZHSCL_V", SqlDbType.Float, this._ZHSCL_V);
            db.AddInParameter(cmd, "@ZHSHT_T", SqlDbType.NVarChar, this._ZHSHT_T);
            db.AddInParameter(cmd, "@ZHSHT_V", SqlDbType.Float, this._ZHSHT_V);
            db.AddInParameter(cmd, "@ZHSDB_T", SqlDbType.NVarChar, this._ZHSDB_T);
            db.AddInParameter(cmd, "@ZHSDB_V", SqlDbType.Float, this._ZHSDB_V);
            db.AddInParameter(cmd, "@GIAP", SqlDbType.Float, this._GIAP);
            db.AddInParameter(cmd, "@GIAO", SqlDbType.Float, this._GIAO);
            db.AddInParameter(cmd, "@USRM", SqlDbType.Int, this._USRM);
            db.AddInParameter(cmd, "@DELE", SqlDbType.Bit, this._DELE);

            db.AddOutParameter(cmd, "@NewDATM", SqlDbType.DateTime, 4);
            db.ExecuteNonQuery(cmd);

            this._DATM = (DateTime)cmd.Parameters["@NewDATM"].Value;
        }
        #endregion Update
        //==========================================================================

        #region Delete
        [Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_DeleteSelf()
        {
            DataPortal_Delete(new RootCriteria(_HSID.Value));
        }

        private void DataPortal_Delete(RootCriteria criteria)
        {
            this.Execute_Delete(criteria);
        }

        protected void Execute_Delete(RootCriteria criteria)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("HOSOBO_DeleteBO");
            db.AddInParameter(cmd, "@DirectDelete", SqlDbType.Bit, criteria.directDelete);
            db.AddInParameter(cmd, "@HSID", SqlDbType.Int, criteria.HSID);
            db.ExecuteNonQuery(cmd);
        }
        #endregion Delete
        //==========================================================================

        #region Internal method
        internal void Insert()
        {
            if (!this.IsDirty) return;
            DataPortal_Insert();
            MarkOld();
        }

        internal void Update()
        {
            if (!this.IsDirty) return;
            DataPortal_Update();
            MarkOld();
        }

        internal void DeleteSelf()
        {
            if (!this.IsDirty) return;
            if (this.IsNew) return;
            DataPortal_Delete(new RootCriteria(_HSID.Value));
            MarkNew();
        }
        #endregion Internal method
        //==========================================================================
    }
}
